package edu.vt.ece.rt.benchmark.intruder;

import java.util.ArrayList;

import edu.vt.ece.rt.benchmark.hashmap.Hashmap;
import edu.vt.ece.rt.dstm.QObject;
import edu.vt.ece.rt.quorum.Resource;

public class FragmentList extends QObject{

	ArrayList<Packet> fragmentListPtr = null;
	String id;

	public FragmentList() {
		fragmentListPtr = null;		
	}

	public FragmentList(String ID, ArrayList<Packet> arr) {
		id = ID;
		fragmentListPtr = arr;
		Resource.putQObject(getId(), this);
	}

	public FragmentList(String ID) {
		id = ID;
		fragmentListPtr = null;
		Resource.putQObject(getId(), this);
	}

	@Override
	public QObject clone() {
		FragmentList f = new FragmentList();
		f.setId(getId());
		f.setVersion(getVersion());

		synchronized (Resource.waitObj) {
			if (fragmentListPtr != null) {
				f.fragmentListPtr = new ArrayList<Packet>();
				for(Packet i : this.fragmentListPtr) {
					f.fragmentListPtr.add(i);
				}
			}
		}
		f.setCloneOwner(getCloneOwner());
		return f;
	}

	@Override
	public String getId() {
		// TODO Auto-generated method stub
		return id;
	}

	public void setId(String ID) {
		id = ID;
	}

}
